package com.example.demo.gouzaoqi;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class java8function {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
//        System.out.println(list);
        System.out.println("输出所有数据:");
        eval(list, n->true);
        System.out.println("输出偶数:");

        eval(list, n-> n%2 == 0 );
        System.out.println("输出大于3的数字:");
        eval(list, n-> n > 3 );

    }

    private static void eval(List<Integer> list,Predicate<Integer> predicate) {
        for (Integer inte:list) {
            if(predicate.test(inte)){
                System.out.println(inte+" ");
            }
        }
    }
}
